package com.moxiao.yfjh.module.blind.controller.app.controller.user;

import com.google.gson.JsonObject;
import com.moxiao.yfjh.framework.common.pojo.CommonResult;
import com.moxiao.yfjh.framework.common.pojo.PageResult;
import com.moxiao.yfjh.framework.common.util.date.DateUtils;
import com.moxiao.yfjh.framework.common.util.number.NumberUtils;
import com.moxiao.yfjh.framework.ip.core.Area;
import com.moxiao.yfjh.framework.ip.core.utils.AreaUtils;
import com.moxiao.yfjh.framework.ip.core.utils.IPUtils;
import com.moxiao.yfjh.framework.web.core.util.WebFrameworkUtils;
import com.moxiao.yfjh.module.activity.service.ActivityInfoApiService;
import com.moxiao.yfjh.module.blind.common.*;
import com.moxiao.yfjh.module.blind.controller.admin.album.vo.BlindMemberAlbumCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.album.vo.BlindMemberAlbumExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.album.vo.BlindMemberAlbumPageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.album.vo.BlindMemberAlbumRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.comment.vo.MemberCommentCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.comment.vo.MemberCommentExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.comment.vo.MemberCommentRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.member.vo.BlindMemberUserCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.member.vo.BlindMemberUserPageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.member.vo.BlindMemberUserRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.member.vo.BlindMemberUserUpdateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberlabel.vo.MemberLabelExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberlabel.vo.MemberLabelRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberusertag.vo.MemberUsertagExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.memberusertag.vo.MemberUsertagPageReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.moment.vo.*;
import com.moxiao.yfjh.module.blind.controller.admin.privilege.vo.MemberPrivilegeExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.privilege.vo.MemberPrivilegeRespVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordCreateReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.recommendRecord.vo.RecommendRecordExportReqVO;
import com.moxiao.yfjh.module.blind.controller.admin.sessionRecord.vo.SessionRecordExportReqVO;
import com.moxiao.yfjh.module.blind.controller.app.controller.user.vo.AppBlindUserPageReqVO;
import com.moxiao.yfjh.module.blind.controller.app.controller.user.vo.AppBlindUserVo;
import com.moxiao.yfjh.module.blind.controller.app.controller.user.vo.AppRecommendRespVo;
import com.moxiao.yfjh.module.blind.controller.app.controller.user.vo.ResidualInterestRespVo;
import com.moxiao.yfjh.module.blind.convert.album.BlindMemberAlbumConvert;
import com.moxiao.yfjh.module.blind.convert.comment.MemberCommentConvert;
import com.moxiao.yfjh.module.blind.convert.member.BlindMemberUserConvert;
import com.moxiao.yfjh.module.blind.convert.memberlabel.MemberLabelConvert;
import com.moxiao.yfjh.module.blind.convert.memberusertag.MemberUsertagConvert;
import com.moxiao.yfjh.module.blind.convert.moment.BlindMemberMomentConvert;
import com.moxiao.yfjh.module.blind.convert.privilege.MemberPrivilegeConvert;
import com.moxiao.yfjh.module.blind.dal.dataobject.album.BlindMemberAlbumDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.basicSetting.BlindBasicSettingDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.comment.MemberCommentDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.member.BlindMemberUserDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberlabel.MemberLabelDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.memberusertag.MemberUsertagDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.moment.BlindMemberMomentDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.privilege.MemberPrivilegeDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.recommendRecord.RecommendRecordDO;
import com.moxiao.yfjh.module.blind.dal.dataobject.sessionRecord.SessionRecordDO;
import com.moxiao.yfjh.module.blind.service.album.BlindMemberAlbumService;
import com.moxiao.yfjh.module.blind.service.background.BackgroundService;
import com.moxiao.yfjh.module.blind.service.basicSetting.BlindBasicSettingService;
import com.moxiao.yfjh.module.blind.service.comment.MemberCommentService;
import com.moxiao.yfjh.module.blind.service.equity.MemberEquityService;
import com.moxiao.yfjh.module.blind.service.member.BlindMemberUserService;
import com.moxiao.yfjh.module.blind.service.memberlabel.MemberLabelService;
import com.moxiao.yfjh.module.blind.service.memberusertag.MemberUsertagService;
import com.moxiao.yfjh.module.blind.service.moment.BlindMemberMomentService;
import com.moxiao.yfjh.module.blind.service.privilege.MemberPrivilegeService;
import com.moxiao.yfjh.module.blind.service.recommendRecord.RecommendRecordService;
import com.moxiao.yfjh.module.blind.service.sessionRecord.SessionRecordService;
import com.moxiao.yfjh.module.system.mq.kafka.KafkaProducer;
import com.moxiao.yfjh.module.system.sms.utils.GreenScanUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.moxiao.yfjh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.moxiao.yfjh.framework.common.pojo.CommonResult.*;
import static com.moxiao.yfjh.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId;
import static com.moxiao.yfjh.module.blind.common.ErrorCodeConstants.ABOUTME_UNIFIED_RETURN;
import static com.moxiao.yfjh.module.blind.enums.ErrorCodeConstants.MEMBER_USER_LOGIN_NOT_EXISTS;

/**
 * @version 1.0
 * @Author zhk
 * @Date 2024/1/10 17:04
 **/

@Tag(name = "用户 APP - 相亲用户个人中心")
@RestController
@RequestMapping("/blind/member/user")
@Validated
@Slf4j
public class AppBlindUserController {

    private static final String PREFIX_USER = "HY";

    // 特殊字符
    private static final Pattern SPECIAL_CHAR_PATTERN = Pattern.compile("[^a-zA-Z0-9\\u4e00-\\u9fa5]");

    @Resource
    private BlindMemberUserService memberUserService;
    @Resource
    private BlindMemberMomentService blindMemberMomentService;
    @Resource
    private GenNoCommonMethod genNoCommonMethod;
    @Resource
    private MemberCommentService memberCommentService;
    @Resource
    private BlindMemberAlbumService memberAlbumService;
    @Resource
    private CommonUse commonUse;
    @Resource
    private BlindBasicSettingService blindBasicSettingService;
    @Resource
    private TencentCloudImUtil tencentCloudImUtil;
    @Resource
    private SysDictEnumUtil sysDictEnumUtil;

    @Resource
    private MemberEquityService memberEquityService;

    @Resource
    private RecommendRecordService recommendRecordService;

    @Resource
    private GreenScanUtils greenScanUtils;

    @Resource
    private CommonRedisUtils commonRedisUtils;

    @Resource
    private RedisTemplate redisTemplate;

    @Resource
    private MemberPrivilegeService memberPrivilegeService;

    @Resource
    private SessionRecordService sessionRecordService;
    @Resource
    private ActivityInfoApiService activityInfoApiService;

    @Resource
    private MemberUsertagService memberUsertagService;

    @Resource
    private MemberLabelService memberLabelService;
    @Autowired
    private KafkaProducer kafkaProducer;
    @Resource
    private BackgroundService backgroundService;
    @Resource
    private StringRedisTemplate stringRedisTemplate;


    @PutMapping("/updateBlindMemberUser")
    @Operation(summary = "更新相亲会员用户")
    public CommonResult<Boolean> updateBlindMemberUser(@Valid @RequestBody BlindMemberUserUpdateReqVO updateReqVO) {
        Long loginUserId = getLoginUserId();
        //用戶当前信息
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(loginUserId);
        if (Objects.isNull(memberUser)) {
            error(401, "获取用户信息失败");
        }
        updateReqVO.setId(loginUserId);
        processAge(updateReqVO);
//        if (Objects.nonNull(updateReqVO.getNickname()) && !Objects.equals(updateReqVO.getNickname(), memberUser.getNickname())) {
//            tencentCloudImUtil.portraitSet(String.valueOf(getLoginUserId()), updateReqVO.getNickname(), null);
//        }
        if (Objects.nonNull(updateReqVO.getAuditAvatar())) {
            //修改头像 重新审核
            updateReqVO.setAuditStatus((byte) 0);
            updateReqVO.setRejectReason("");
        }
        if (StringUtils.isNotEmpty(memberUser.getNickname())) {
            // 不修改昵称，由kafka消费者来修改:listenNickNameConsumer
            updateReqVO.setNickname(memberUser.getNickname());
        }
        //内心独白 innerMonologue
        if (StringUtils.isNotEmpty(updateReqVO.getInnerMonologue())) {
            //  kafka 内心独白-生产消息发送
            JsonObject jsonObject = new JsonObject();
            jsonObject.addProperty("content", updateReqVO.getInnerMonologue());
            jsonObject.addProperty("id", memberUser.getId());
            kafkaProducer.addSendGreenTextScan(jsonObject);
        }

        // 此处kafka消费处理:listenInnerMonologueConsumer
        if (StringUtils.isNotEmpty(memberUser.getInnerMonologue())) {
            updateReqVO.setInnerMonologue(memberUser.getInnerMonologue());
        }
        if (StringUtils.isNotEmpty(updateReqVO.getAboutMe())) {
            Map map = null;
            try {
                map = greenScanUtils.greeTextScan(updateReqVO.getAboutMe());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (!Objects.equals(map.get("suggestion"), "pass")) {
                throw exception(ABOUTME_UNIFIED_RETURN);
            }
        }
        memberUserService.updateMemberUser(updateReqVO);
        return success(true);
    }

    public static boolean containsSpecialChar(String nickname) {
        return SPECIAL_CHAR_PATTERN.matcher(nickname).find();
    }

    private void processAge(BlindMemberUserUpdateReqVO updateReqVO) {
        if (Objects.nonNull(updateReqVO.getBirthday())) {
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            try {
                date = sdf.parse(updateReqVO.getBirthday());
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
            updateReqVO.setAge(commonUse.countAge(date));
        }
    }


    @PostMapping("/createMemberUser")
    @Operation(summary = "创建相亲会员用户")
    public CommonResult<Long> createMemberUser(@Valid @RequestBody BlindMemberUserCreateReqVO createReqVO) {
        addUserNo(createReqVO);
        Long memberUser = memberUserService.createMemberUser(createReqVO);
        if (Objects.nonNull(memberUser)) {
            BlindMemberUserDO memberUserDo = memberUserService.getMemberUser(memberUser);
            commonRedisUtils.createMemberToRedis(memberUser, memberUserDo);
        }

        return success(memberUser);
    }

    @PostMapping("/createMemberUserTag")
    @Operation(summary = "创建相亲用户标签")
    public CommonResult<Boolean> createMemberUserTag(@Valid @RequestBody List<Long> labelRespVOS) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }
        memberUsertagService.createUserTag(labelRespVOS, loginUserId);
        return success(Boolean.TRUE);
    }

    @PutMapping("/updateMemberUserTag")
    @Operation(summary = "更新相亲用户标签")
    public CommonResult<Boolean> updateMemberUserTag(@Valid @RequestBody List<Long> labelRespVOS) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }
        memberUsertagService.updateUserTag(labelRespVOS, loginUserId);
        return success(true);
    }

    @GetMapping("/getMemberLabel")
    @Operation(summary = "获得相亲标签库分页")
    public CommonResult<List<MemberLabelRespVO>> getMemberLabel() {
        List<MemberLabelDO> memberLabelList = memberLabelService.getMemberLabelList(new MemberLabelExportReqVO());
        return success(MemberLabelConvert.INSTANCE.convertList(memberLabelList));
    }

    @GetMapping("/getMemberUserTag")
    @Operation(summary = "获得相亲用户标签分页")
    public CommonResult<List<Long>> getMemberUserTag(@Valid MemberUsertagPageReqVO pageVO) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }

        Long userId;
        if (Objects.nonNull(pageVO.getUserId())) {
            userId = pageVO.getUserId();
        } else {
            userId = loginUserId;
        }
        MemberUsertagExportReqVO exportReqVO = new MemberUsertagExportReqVO();
        exportReqVO.setUserId(userId);
        List<MemberUsertagDO> memberUsertagList = memberUsertagService.getMemberUsertagList(exportReqVO);
        return success(memberUsertagList.stream().map(MemberUsertagDO::getLabelId).collect(Collectors.toList()));
    }


    @GetMapping("/getMemberUser")
    @Operation(summary = "获得相亲会员用户")
    public CommonResult<BlindMemberUserRespVO> getMemberUser() {
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(getLoginUserId());
        if (Objects.isNull(memberUser)) {
            return error(401, "获取用户信息失败");
        }
        BlindMemberUserRespVO blindMemberUserRespVO = BlindMemberUserConvert.INSTANCE.convert(memberUser);
        buildAreaName(blindMemberUserRespVO);
        blindMemberUserRespVO.setHaveNameAuth(blindMemberUserRespVO.getHaveReal());
        MemberUsertagExportReqVO exportReqVO = new MemberUsertagExportReqVO();
        exportReqVO.setUserId(blindMemberUserRespVO.getId());
        List<MemberUsertagDO> memberUsertagList = memberUsertagService.getMemberUsertagList(exportReqVO);
        blindMemberUserRespVO.setMemberUserTagRespVOS(MemberUsertagConvert.INSTANCE.convertList(memberUsertagList));
        Byte sex = 1;
        if (Objects.equals(blindMemberUserRespVO.getSex(), sex)) {
            blindMemberUserRespVO.setBgUrl(backgroundService.getRandomBackground(3));
        } else {
            blindMemberUserRespVO.setBgUrl(backgroundService.getRandomBackground(4));
        }
        return success(blindMemberUserRespVO);
    }

    @GetMapping("/getAppointMemberUser")
    @Operation(summary = "获得指定用户会员信息数据")
    @Parameter(name = "userId", description = "昵称", required = true)
    public CommonResult<BlindMemberUserRespVO> getAppointMemberUser(@RequestParam("userId") Long userId) {
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(userId);
        if (Objects.isNull(memberUser)) {
            return buildSuccess(null, "查不到此人！");
        }
        BlindMemberUserRespVO blindMemberUserRespVO = BlindMemberUserConvert.INSTANCE.convert(memberUser);
        buildAreaName(blindMemberUserRespVO);
        MemberUsertagExportReqVO exportReqVO = new MemberUsertagExportReqVO();
        exportReqVO.setUserId(blindMemberUserRespVO.getId());
        List<MemberUsertagDO> memberUsertagList = memberUsertagService.getMemberUsertagList(exportReqVO);
        blindMemberUserRespVO.setMemberUserTagRespVOS(MemberUsertagConvert.INSTANCE.convertList(memberUsertagList));
        //1.添加用户相册
        BlindMemberAlbumExportReqVO albumReqVO = new BlindMemberAlbumExportReqVO();
        albumReqVO.setUserId(blindMemberUserRespVO.getId());
        blindMemberUserRespVO.setAlbumDOS(memberAlbumService.getMemberAlbumList(albumReqVO));
        //2.地址信息
        buildAreaName(blindMemberUserRespVO);
        //3.补充枚举名称
        sysDictEnumUtil.suppleNameDict(blindMemberUserRespVO);
        //4.用户动态
        BlindMemberMomentExportReqVO momentReqVO = new BlindMemberMomentExportReqVO();
        momentReqVO.setUserId(blindMemberUserRespVO.getId());
        blindMemberUserRespVO.setBlindMemberMomentDOList(blindMemberMomentService.getMemberMomentList(momentReqVO));
        //5.IP属地
        if (StringUtils.isNotBlank(blindMemberUserRespVO.getRegisterIp())) {
            Area area = IPUtils.getArea(blindMemberUserRespVO.getRegisterIp());
            String city = AreaUtils.format(area.getId());
            blindMemberUserRespVO.setIpCity(city);
        }
        //6.地理位置 距离
        String userPosition = memberUser.getPosition();
        String matchPosition = blindMemberUserRespVO.getPosition();
        if (StringUtils.isNotEmpty(userPosition) && StringUtils.isNotEmpty(matchPosition)) {
            DecimalFormat df = new DecimalFormat("#0.00");
            String[] userPositionSplit = userPosition.split(",");
            String[] matchPositionSplit = matchPosition.split(",");
            double distance = NumberUtils.getDistance(Double.parseDouble(userPositionSplit[0]), Double.parseDouble(userPositionSplit[1]),
                    Double.parseDouble(matchPositionSplit[0]), Double.parseDouble(matchPositionSplit[1]));
            blindMemberUserRespVO.setGetDistance(String.valueOf(df.format(distance)));
        } else {
            blindMemberUserRespVO.setGetDistance(null);
        }
        //7.是否实名
        blindMemberUserRespVO.setHaveNameAuth(blindMemberUserRespVO.getHaveReal());
        Byte sex = 1;
        if (Objects.equals(blindMemberUserRespVO.getSex(), sex)) {
            blindMemberUserRespVO.setBgUrl(backgroundService.getRandomBackground(3));
        } else {
            blindMemberUserRespVO.setBgUrl(backgroundService.getRandomBackground(4));
        }
        return success(blindMemberUserRespVO);
    }

    @GetMapping("/nickNameDuplicated")
    @Operation(summary = "昵称是否重复")
    @Parameter(name = "nickName", description = "用户id", required = true)
    public CommonResult<Boolean> nickNameDuplicated(@RequestParam("nickName") String nickName) {
        //判断昵称中是否有特殊字符
        if (containsSpecialChar(nickName)) {
            return buildSuccess(Boolean.TRUE, "当前昵称存在特殊字符，请更换昵称");
        }
        // toto count
        int memberUser = memberUserService.getUserCount(nickName);
        if (memberUser > 0) {
            return buildSuccess(true, "您输入的昵称已存在！请重新输入");
        }
        BlindMemberUserDO user = memberUserService.getMemberUser(getLoginUserId());
        if (Objects.isNull(user)) {
            return error(401, "获取个人信息失败");
        }
        //  kafka 用户昵称-生产消息发送
        JsonObject jsonObject = new JsonObject();
        if (StringUtils.isNotEmpty(user.getNickname())) {
            jsonObject.addProperty("old_nickName", user.getNickname());
        } else {
            jsonObject.addProperty("old_nickName", "用户" + user.getId());
        }
        jsonObject.addProperty("nickName", nickName);
        jsonObject.addProperty("id", getLoginUserId());
        kafkaProducer.addSendNickName(jsonObject);
        return buildSuccess(false, "");
    }

    public static String processNickname(String nickname, int maxLength) {
        if (nickname == null || nickname.isEmpty()) {
            return ""; // 昵称不能为空
        }

        // 使用正则表达式替换特殊字符
        nickname = nickname.replaceAll("[^a-zA-Z0-9]", "");

        // 转换为小写
        nickname = nickname.toLowerCase();

        // 检查长度并截断
        if (nickname.length() > maxLength) {
            nickname = nickname.substring(0, maxLength);
        }

        return nickname;
    }


    @GetMapping("/userCondition")
    @Operation(summary = "精准搜索用户信息")
    @Parameter(name = "userNo", description = "用户编号", required = true)
    public CommonResult<BlindMemberUserRespVO> userCondition(@RequestParam("userNo") String userNo) {
        // 获得当前挡路人信息
        BlindMemberUserDO userDO = memberUserService.getMemberUser(getLoginUserId());
        if (Objects.isNull(userDO)) {
            return error(401, "获取个人信息失败");
        }
        byte sex = -1;

        if (Objects.nonNull(userDO)) {
            if (Objects.equals(userDO.getSex(), (byte) 1)) {
                sex = 2;
            } else {
                sex = 1;
            }
        }
        BlindMemberUserDO memberUser = memberUserService.userCondition(userNo, sex);
        if (Objects.nonNull(memberUser)) {
            BlindMemberUserRespVO blindMemberUserRespVO = BlindMemberUserConvert.INSTANCE.convert(memberUser);
            this.buildBlindMemberUserRespVO(blindMemberUserRespVO, memberUser);
            return success(blindMemberUserRespVO);
        } else {
            return error(500, "未找到会员信息");
        }
    }

    @GetMapping("/getBlindMemberUserPage")
    @Operation(summary = "获得相亲会员用户分页")
    public CommonResult<PageResult<BlindMemberUserRespVO>> getBlindMemberUserPage(@Valid BlindMemberUserPageReqVO pageVO) {
        PageResult<BlindMemberUserDO> pageResult = memberUserService.getMemberUserPage(pageVO);
        return success(BlindMemberUserConvert.INSTANCE.convertPage(pageResult));
    }


    @PostMapping("/createBlindMemberAlbum")
    @Operation(summary = "创建相亲会员相册")
    public CommonResult<Boolean> createBlindMemberAlbum(@Valid @RequestBody List<BlindMemberAlbumCreateReqVO> createReqVO) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }
        memberAlbumService.createMemberAlbum(createReqVO, loginUserId);
        return success(true);
    }

    @PutMapping("/updateBlindMemberAlbum")
    @Operation(summary = "更新相亲会员相册")
    public CommonResult<Boolean> updateBlindMemberAlbum(@Valid @RequestBody List<BlindMemberAlbumCreateReqVO> createReqVO) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }
        memberAlbumService.updateMemberAlbum(createReqVO, loginUserId);
        return success(true);
    }

    @DeleteMapping("/deleteBlindMemberAlbum")
    @Operation(summary = "删除相亲会员相册")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBlindMemberAlbum(@RequestParam("id") Long id) {
        memberAlbumService.deleteMemberAlbum(id);
        return success(true);
    }

    @GetMapping("/getBlindMemberAlbumPage")
    @Operation(summary = "获得相亲会员相册分页")
    public CommonResult<PageResult<BlindMemberAlbumRespVO>> getBlindMemberAlbumPage(@Valid BlindMemberAlbumPageReqVO pageVO) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }
        pageVO.setUserId(loginUserId);
        PageResult<BlindMemberAlbumDO> pageResult = memberAlbumService.getMemberAlbumPage(pageVO);
        return success(BlindMemberAlbumConvert.INSTANCE.convertPage(pageResult));
    }


    private static final String VIDEO_URL = "videoUrl:";

    @PostMapping("/createBlindMemberMoment")
    @Operation(summary = "创建相亲会员动态")
    public CommonResult<String> createBlindMemberMoment(@Valid @RequestBody BlindMemberMomentCreateReqVO createReqVO) {
        genNoCommonMethod.addMementNo(createReqVO);
        buildCreateReqVO(createReqVO);
        if (StringUtils.isNotEmpty(buildCreateReqVO(createReqVO))) {
            return error(300, buildCreateReqVO(createReqVO));
        }
        //异步处理videoUrl
//        CompletableFuture<Byte> future = CompletableFuture.supplyAsync(() -> {
//            try {
//                if (StringUtils.isNotEmpty(createReqVO.getVideoUrl())){
//                    try {
//                        Map videoTaskScan = greenScanUtils.createVideoTaskScan(createReqVO.getVideoUrl());
//                        if (MapUtils.isNotEmpty(videoTaskScan)){
//                            String taskId = (String)videoTaskScan.get("taskId");
//                            String s = VIDEO_URL + createReqVO.getVideoUrl();
//                            redisTemplate.opsForValue().set(s,taskId);
//                            Map map = greenScanUtils.videoScan(taskId);
//                            System.out.println(JSON.toJSONString(map));
//                            if (MapUtils.isNotEmpty(map)){
//                                if(Objects.equals(map.get("suggestion"),"pass")){
//                                   return (byte) 1;
//                                }else {
//                                   return (byte) 2;
//                                }
//                            }else {
//                                return (byte) 0;
//                            }
//                        }
//                    } catch (Exception e) {
//                        throw new RuntimeException(e);
//                    }
//                }
//                TimeUnit.SECONDS.sleep(2);
//            } catch (InterruptedException e) {
//                throw new RuntimeException(e);
//            }
//            return (byte) 0;
//        });
//        // 判断任务是否完成
//        while (!future.isDone()) {
//            Byte result = null;
//            try {
//                result = future.get();
//                if (Objects.equals(result,(byte) 0)){
//                    try {
//                        BlindMemberMomentDO blindMemberMomentDO = blindMemberMomentService.getMemberMoment(memberMoment);
//                        BlindMemberMomentUpdateReqVO updateReqVO = new BlindMemberMomentUpdateReqVO();
//                        updateReqVO.setId(memberMoment);
//                        if (Objects.nonNull(blindMemberMomentDO) && Objects.equals(blindMemberMomentDO.getAuditStatus() ,(byte) 0)){
//                            String s = VIDEO_URL + createReqVO.getVideoUrl();
//                            String videoKey = (String) redisTemplate.opsForValue().get(s);
//                            Map map = greenScanUtils.queryVideoScan(videoKey);
//                            if (MapUtils.isNotEmpty(map)){
//                                if(Objects.equals(map.get("suggestion"),"pass")){
//                                    updateReqVO.setAuditStatus((byte) 1);
//                                    updateReqVO.setAuitTime(LocalDateTime.now());
//                                }else {
//                                    updateReqVO.setRejectReason("有违规内容，阿里云审核失败！");
//                                    updateReqVO.setAuitTime(LocalDateTime.now());
//                                    updateReqVO.setAuditStatus((byte) 2);
//                                    messageUtils.createVideoAuditMessage(blindMemberMomentDO);
//                                }
//                            }
//                            blindMemberMomentService.updateMemberMoment(updateReqVO);
//                        }
//
//                    } catch (Exception e) {
//                        throw new RuntimeException(e);
//                    }
//                }else if((Objects.equals(result,(byte) 2))){
//
//                    BlindMemberMomentUpdateReqVO updateReqVO = new BlindMemberMomentUpdateReqVO();
//                    updateReqVO.setId(memberMoment);
//                    updateReqVO.setRejectReason("有违规内容，阿里云审核失败！");
//                    updateReqVO.setAuitTime(LocalDateTime.now());
//                    updateReqVO.setAuditStatus((byte) 2);
//                    blindMemberMomentService.updateMemberMoment(updateReqVO);
//
//                    BlindMemberMomentDO blindMemberMomentDO = blindMemberMomentService.getMemberMoment(memberMoment);
//                    if (Objects.nonNull(blindMemberMomentDO){
//                        messageUtils.createVideoAuditMessage(blindMemberMomentDO);
//                    }
//                }
//            } catch (Exception e) {
//                throw new RuntimeException(e);
//            }
//        }
        blindMemberMomentService.createMemberMoment(createReqVO);
        if (Objects.nonNull(createReqVO.getVideoUrl())) {
            return error(300, "审核中");
        }
        return success("审核完成");
    }

    private String buildCreateReqVO(BlindMemberMomentCreateReqVO createReqVO) {
        if (StringUtils.isNotEmpty(createReqVO.getVideoUrl())) {
            createReqVO.setType((byte) 2);
        } else if (StringUtils.isNotEmpty(createReqVO.getImgUrl())) {
            createReqVO.setType((byte) 1);
        } else {
            createReqVO.setType((byte) 0);
            try {
                Map map = greenScanUtils.greeTextScan(createReqVO.getContent());
                if (MapUtils.isNotEmpty(map)) {
                    if (Objects.equals(map.get("suggestion"), "pass")) {
                        createReqVO.setStatus((byte) 1);
                        return Strings.EMPTY;
                    } else {
                        createReqVO.setRejectReason(String.valueOf(map.get("reason")));
                        createReqVO.setAuitTime(LocalDateTime.now());
                        createReqVO.setAuditStatus((byte) 2);
                        return String.valueOf(map.get("reason"));
                    }
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return Strings.EMPTY;
    }

    @GetMapping("/getBlindMemberMomentPage")
    @Operation(summary = "获得相亲会员动态分页")
    public CommonResult<PageResult<BlindMemberMomentRespVO>> getBlindMemberMomentPage(@Valid BlindMemberMomentPageReqVO pageVO) {

        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }
        if (Objects.nonNull(pageVO.getUserId())) {
            pageVO.setUserId(pageVO.getUserId());
        } else {
            pageVO.setUserId(loginUserId);
        }
        PageResult<BlindMemberMomentDO> pageResult = blindMemberMomentService.getMemberMomentPage(pageVO);
        PageResult<BlindMemberMomentRespVO> respVOPageResult = BlindMemberMomentConvert.INSTANCE.convertPage(pageResult);
        if (Objects.nonNull(respVOPageResult)) {
            List<BlindMemberMomentRespVO> list = respVOPageResult.getList();
            if (CollectionUtils.isNotEmpty(list)) {
                list.forEach(blindMemberMomentRespVO -> {
                    MemberCommentExportReqVO reqVO = new MemberCommentExportReqVO();
                    reqVO.setMomentId(blindMemberMomentRespVO.getId());
                    if (!Objects.equals(pageVO.getUserId(), getLoginUserId())) {
                        reqVO.setUserId(getLoginUserId());
                    }
                    List<MemberCommentDO> memberCommentDOList = memberCommentService.getMemberCommentList(reqVO);
                    List<MemberCommentRespVO> memberCommentRespVOS = MemberCommentConvert.INSTANCE.convertList(memberCommentDOList);
                    //过滤 规定时间内未审核
                    BlindBasicSettingDO basicSetting = blindBasicSettingService.getBasicSetting(1L);
                    if (Objects.nonNull(basicSetting)) {
                        LocalDateTime now = LocalDateTime.now();
                        int processTime = basicSetting.getProcessTime() * 60;
                        memberCommentRespVOS = memberCommentRespVOS.stream().filter(
                                s -> Objects.equals(s.getStatus(), (byte) 1) || (Objects.equals(s.getStatus(), (byte) 0) && Objects.isNull(s.getAuitTime())
                                        && Duration.between(s.getCreateTime(), now).getSeconds() < processTime)
                        ).collect(Collectors.toList());
                    }

                    if (CollectionUtils.isNotEmpty(memberCommentRespVOS)) {
                        memberCommentRespVOS.forEach(memberCommentRespVO -> {
                            Long userId = memberCommentRespVO.getUserId();
                            BlindMemberUserDO memberUser = memberUserService.getMemberUser(userId);
                            memberCommentRespVO.setAvatar(memberUser.getAvatar());
                            memberCommentRespVO.setNickname(memberUser.getNickname());
                        });
                    }
                    blindMemberMomentRespVO.setMemberCommentDOList(memberCommentRespVOS);
                    blindMemberMomentRespVO.setTimeHours(DateUtils.getString(blindMemberMomentRespVO.getCreateTime()));
                });
            }
        }
        return success(respVOPageResult);
    }


    @GetMapping("/getBlindMemberMomentStatistics")
    @Operation(summary = "获得我的会员动态统计数据")
    public CommonResult<BlindMementStatisticsVo> getBlindMemberMomentStatistics(@Valid AppBlindUserVo appBlindUserVo) {
        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }

        Long userId;
        if (Objects.nonNull(appBlindUserVo.getUserId())) {
            userId = appBlindUserVo.getUserId();
        } else {
            userId = loginUserId;
        }
        BlindMementStatisticsVo memberMomentStatistics = blindMemberMomentService.getMemberMomentStatistics(userId);
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(userId);
        if (Objects.nonNull(memberUser)) {
            memberMomentStatistics.setAvatar(memberUser.getAvatar());
            memberMomentStatistics.setNickname(memberUser.getNickname());
            memberMomentStatistics.setHaveNameAuth(StringUtils.isNotEmpty(memberUser.getIdNumber()) ? 1 : 0);
            memberMomentStatistics.setAuditStatus(memberUser.getAuditStatus());
            memberMomentStatistics.setAuditAvatar(memberUser.getAuditAvatar());
            memberMomentStatistics.setHaveMember(memberUser.getHaveMember());
            memberMomentStatistics.setAge(memberUser.getAge());
            BlindMemberUserRespVO blindMemberUserRespVO = BlindMemberUserConvert.INSTANCE.convert(memberUser);
            //3.补充枚举名称
            sysDictEnumUtil.suppleNameDict(blindMemberUserRespVO);
            String area = AreaUtils.getAreaName(memberUser.getAreaId());
            String[] parts = area.split("/");
            if (parts.length >= 2) {
                String middlePart = parts[1];
                memberMomentStatistics.setCity(middlePart);
            }else{
                memberMomentStatistics.setCity(area);
            }
            if(StringUtils.isNotEmpty(memberUser.getCareer())){
                memberMomentStatistics.setCareer(memberUser.getCareer());
            }
        }
        if (Objects.nonNull(appBlindUserVo.getUserId())) {
            BlindBasicSettingDO basicSetting = blindBasicSettingService.getBasicSetting(1L);
            if (Objects.nonNull(basicSetting)) {
                if (Objects.equals(basicSetting.getCommentAuth(), (byte) 1)) {
                    memberMomentStatistics.setIsFriend(Boolean.FALSE);
                } else {
                    SessionRecordExportReqVO exportReqVO = new SessionRecordExportReqVO();
                    exportReqVO.setFounder(String.valueOf(appBlindUserVo.getUserId()));
                    exportReqVO.setParticipants(String.valueOf(getLoginUserId()));
                    List<SessionRecordDO> sessionRecordList = sessionRecordService.getRecordList(exportReqVO);
                    if (CollectionUtils.isNotEmpty(sessionRecordList)) {
                        memberMomentStatistics.setIsFriend(Boolean.FALSE);
                    } else {
                        memberMomentStatistics.setIsFriend(Boolean.TRUE);
                    }
                }
            }
        }
        return success(memberMomentStatistics);
    }


    @GetMapping("/getOthersBlindMomentStatistics")
    @Operation(summary = "获得我的会员动态统计数据")
    @Parameter(name = "id", description = "编号", example = "1024")
    public CommonResult<BlindMementStatisticsVo> getOthersBlindMomentStatistics(@RequestParam("id") Long id) {
        BlindMementStatisticsVo memberMomentStatistics = blindMemberMomentService.getMemberMomentStatistics(id);
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(id);
        if (Objects.nonNull(memberUser)) {
            memberMomentStatistics.setAvatar(memberUser.getAvatar());
        }
        return success(memberMomentStatistics);
    }


    @PostMapping("/createBlindMemberComment")
    @Operation(summary = "创建相亲会员评价")
    public CommonResult<Long> createBlindMemberComment(@Valid @RequestBody MemberCommentCreateReqVO createReqVO) {
        genNoCommonMethod.addCommentNo(createReqVO);
        try {
            Map map = greenScanUtils.greeTextScan(createReqVO.getContent());
            if (MapUtils.isNotEmpty(map)) {
                if (!Objects.equals(map.get("suggestion"), "pass")) {
                    return error(500, "阿里云审核失败，评论中存在违规信息!");
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return success(memberCommentService.createMemberComment(createReqVO));
    }

    @DeleteMapping("/deleteBlindMemberComment")
    @Operation(summary = "删除相亲会员评价")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBlindMemberComment(@RequestParam("id") Long id) {
        memberCommentService.deleteMemberComment(id);
        return success(true);
    }


    @DeleteMapping("/deleteBlindMemberMoment")
    @Operation(summary = "删除相亲会员动态")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteBlindMemberMoment(@RequestParam("id") Long id) {
        blindMemberMomentService.deleteMemberMoment(id);
        return success(true);
    }
    /*

    超级推荐
    喜欢 取5个 随机


    20个取数据库 从redis按页做缓存 随机
     */

    @GetMapping("/basicMatchBlindMembers")
    @Operation(summary = "基础匹配数据")
    @Parameter(name = "haveMember", description = "是否是会员", required = true)
    public CommonResult<List<BlindMemberUserRespVO>> basicMatchBlindMembers(@RequestParam("haveMember") Integer haveMember) {

        Long loginUserId = getLoginUserId();
        if (Objects.isNull(loginUserId)) {
            return error(401, "获取个人信息失败");
        }

        if (!processRequest()) {
            return error(500, "匹配中，请等待您的soul到来呦～");
        }
        // 当前会员用户没有必填信息时，重新跳入登录页，重新登录后进入必填页
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(loginUserId);
        if (Objects.nonNull(memberUser.getSex())) {
            if (memberUser.getSex() == 0 || memberUser.getSex() == -1) {
                throw exception(MEMBER_USER_LOGIN_NOT_EXISTS);
            }
        } else {
            throw exception(MEMBER_USER_LOGIN_NOT_EXISTS);
        }

        List<BlindMemberUserDO> blindMemberUserDOS = null;
        try {
            blindMemberUserDOS = memberUserService.basicMatchBlindMembers(processMatchDegree(haveMember), loginUserId, memberUser);
        } catch (IOException e) {
            return error(500, "匹配中，请等待您的soul到来呦～");
        }
        List<BlindMemberUserRespVO> memberUserRespVOS = BlindMemberUserConvert.INSTANCE.convertList(blindMemberUserDOS);
        if (CollectionUtils.isNotEmpty(memberUserRespVOS)) {
            memberUserRespVOS.forEach(blindMemberUserRespVO ->
                    buildBlindMemberUserRespVO(blindMemberUserRespVO, memberUser));
        }

        return success(memberUserRespVOS);
    }

    /**
     * 请求1000返回刷新中
     */
    private static final String BASIC_REDIS_KEY = "basicMatchBlindMembers:redis";

    private boolean processRequest() {
        String s = stringRedisTemplate.opsForValue().get(BASIC_REDIS_KEY);
        if (StringUtils.isNotEmpty(s)) {
            if (Integer.parseInt(s) >= 1000) {
                stringRedisTemplate.delete(BASIC_REDIS_KEY);
                return false;
            }
            stringRedisTemplate.opsForValue().increment(BASIC_REDIS_KEY, 1);
        } else {
            stringRedisTemplate.opsForValue().set(BASIC_REDIS_KEY, "1");
        }
        return true;
    }

    /**
     * 计算匹配比例
     *
     * @param haveMember
     * @return
     */
    private Integer processMatchDegree(Integer haveMember) {
        BlindBasicSettingDO basicSetting = blindBasicSettingService.getBasicSetting(1L);
        Integer matchDegree;
        if (Objects.equals(haveMember, 1)) {
            matchDegree = basicSetting.getMatchUser();
        } else {
            matchDegree = basicSetting.getMatchNonUser();
        }
        return matchDegree;
    }

    @GetMapping("/searchBlindMembers")
    @Operation(summary = "搜索匹配用户")
    public CommonResult<PageResult<BlindMemberUserRespVO>> searchBlindMembers(@Valid AppBlindUserPageReqVO pageVO) {

        // 获得当前挡路人信息
        BlindMemberUserDO userDO = memberUserService.getMemberUser(getLoginUserId());
        if (Objects.isNull(userDO)) {
            return error(401, "获取个人信息失败");
        }
        byte sex = -1;
        if (Objects.nonNull(userDO)) {
            if (Objects.equals(userDO.getSex(), (byte) 1)) {
                sex = 2;
            } else {
                sex = 1;
            }
        } else {
            return error(401, "未获取到会员用户登录信息，请重新登录！");
        }

        pageVO.setSex(sex);
//        照片数量、动态数量
        PageResult<BlindMemberUserDO> pageResult = memberUserService.searchBlindMembers(pageVO);
        PageResult<BlindMemberUserRespVO> blindMemberUserRespVOPageResult = BlindMemberUserConvert.INSTANCE.convertPage(pageResult);
        if (Objects.nonNull(blindMemberUserRespVOPageResult)) {
            List<BlindMemberUserRespVO> blindMemberUserRespVOS = blindMemberUserRespVOPageResult.getList();
            if (CollectionUtils.isNotEmpty(blindMemberUserRespVOS)) {
                blindMemberUserRespVOS.forEach(s -> {
                    buildBlindMemberUserRespVO(s, userDO);
                });
            }
        }
        return success(blindMemberUserRespVOPageResult);
    }


    @GetMapping("/memberResidualInterest")
    @Operation(summary = "会员剩余权益")
    public CommonResult<ResidualInterestRespVo> memberResidualInterest() {
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(getLoginUserId());
        if (Objects.isNull(memberUser)) {
            return error(401, "获取用户信息失败");
        }
        ResidualInterestRespVo residualInterestRespVo = new ResidualInterestRespVo();

        residualInterestRespVo.setUserLevel(memberUser.getUserLevel());
        residualInterestRespVo.setNickName(memberUser.getNickname());
        LocalDateTime memberEndTime = memberUser.getMemberEndTime();
        residualInterestRespVo.setMemberEnd(memberEndTime);
        residualInterestRespVo.setAvatar(memberUser.getAvatar());
        long days = ChronoUnit.DAYS.between(LocalDateTime.now(), memberEndTime);
        residualInterestRespVo.setRemainingDays(days);
        MemberPrivilegeExportReqVO privilegeReqVO = new MemberPrivilegeExportReqVO();
        if (Objects.equals(memberUser.getUserLevel(), (byte) 1)) {
            privilegeReqVO.setLevelId(1L);
        } else {
            privilegeReqVO.setLevelId(2L);
        }
        privilegeReqVO.setStatus((byte) 1);
        //会员特权
        List<MemberPrivilegeDO> memberPrivilegeList = memberPrivilegeService.getMemberPrivilegeList(privilegeReqVO);
        List<MemberPrivilegeRespVO> memberPrivilegeRespVOS = MemberPrivilegeConvert.INSTANCE.convertList(memberPrivilegeList);
        if (CollectionUtils.isNotEmpty(memberPrivilegeRespVOS)) {
            memberPrivilegeRespVOS.forEach(memberPrivilegeRespVO -> {
                Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(new Date());
                Date lastDayOfMonth = DateUtils.getLastDayOfMonth(new Date());
                Long loginUserId = WebFrameworkUtils.getLoginUserId();
                if (Objects.equals(memberPrivilegeRespVO.getPrivilegeName(), "打招呼")) {
                    Long forceNum = memberEquityService.memberEquityNum(loginUserId, "打招呼", firstDayOfMonth, lastDayOfMonth);
                    Long i = Long.parseLong(memberPrivilegeRespVO.getPrivilegeNum()) - forceNum;
                    memberPrivilegeRespVO.setRemainingNum(i);
                } else if (Objects.equals(memberPrivilegeRespVO.getPrivilegeName(), "强制匹配")) {
                    Long forceNum1 = memberEquityService.memberEquityNum(loginUserId, "强制匹配", firstDayOfMonth, lastDayOfMonth);
                    Long a = Long.parseLong(memberPrivilegeRespVO.getPrivilegeNum()) - forceNum1;
                    memberPrivilegeRespVO.setRemainingNum(a);
                } else if (Objects.equals(memberPrivilegeRespVO.getPrivilegeName(), "发布活动")) {
                    MemberPrivilegeDO memberPrivilegeDO = memberPrivilegeService.getPrivilege("发布活动", 1L);
                    Integer activity_num = activityInfoApiService.getActivityInfoApiNum(getLoginUserId());
                    Long b = Long.parseLong(memberPrivilegeDO.getPrivilegeNum()) - activity_num.longValue();
                    memberPrivilegeRespVO.setRemainingNum(b);
                } else if (Objects.equals(memberPrivilegeRespVO.getPrivilegeName(), "喜欢")) {
                    Long forceNum = memberEquityService.memberEquityNum(loginUserId, "喜欢我", firstDayOfMonth, lastDayOfMonth);
                    Long a = Long.parseLong(memberPrivilegeRespVO.getPrivilegeNum()) - forceNum;
                    memberPrivilegeRespVO.setRemainingNum(a);
                }
            });
        }
        residualInterestRespVo.setListPrivilege(memberPrivilegeRespVOS);

        return success(residualInterestRespVo);
    }

    @GetMapping("/superRecommendedRemaining")
    @Operation(summary = "超级推荐剩余权益")
    public CommonResult<AppRecommendRespVo> superRecommendedRemaining() {
        AppRecommendRespVo appRecommendRespVo = new AppRecommendRespVo();
        Long loginUserId = getLoginUserId();
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(loginUserId);
        if (Objects.isNull(memberUser)) {
            return error(401, "获取用户信息失败");
        }
        RecommendRecordExportReqVO recommendRecordReqVO = new RecommendRecordExportReqVO();
        recommendRecordReqVO.setUserId(loginUserId);
        List<RecommendRecordDO> recommendRecordList = recommendRecordService.getRecommendRecordList(recommendRecordReqVO);
        appRecommendRespVo.setRecommendRecordDOList(recommendRecordList);
        int i = Integer.parseInt(memberUser.getRecommendNum()) - recommendRecordList.size();
        appRecommendRespVo.setNum(i);
        return success(appRecommendRespVo);
    }

    @GetMapping("/usedSuperRecommended")
    @Operation(summary = "使用超级推荐")
    public CommonResult<Boolean> usedSuperRecommended() {
        Long loginUserId = getLoginUserId();
        BlindMemberUserDO memberUser = memberUserService.getMemberUser(loginUserId);
        if (Objects.isNull(memberUser)) {
            return error(401, "获取用户信息失败");
        }
        if (Objects.equals(memberUser.getHaveRecommend(), (byte) 0)) {
            return error(500, "您未购买超级推荐服务！");
        }
        String recommendNum = memberUser.getRecommendNum();
        RecommendRecordExportReqVO exportReqVO = new RecommendRecordExportReqVO();
        exportReqVO.setUserId(loginUserId);
        List<RecommendRecordDO> recommendRecordList = recommendRecordService.getRecommendRecordList(exportReqVO);
        if (recommendRecordList.size() >= Integer.parseInt(recommendNum)) {
            return error(500, "您购买的超级推荐服务次数已用尽！");
        }

        //添加使用超级推荐记录
        RecommendRecordCreateReqVO createReqVO = new RecommendRecordCreateReqVO();
        LocalDateTime nowDateTimePlus1 = LocalDateTime.now().plusDays(1L);
        createReqVO.setBeginTime(LocalDateTime.now());
        createReqVO.setEndTime(nowDateTimePlus1);
        createReqVO.setUserId(getLoginUserId());
        createReqVO.setNum("1");
        createReqVO.setEquityName("超级推荐");
        recommendRecordService.createRecommendRecord(createReqVO);

        //更新超级推荐时间
        BlindMemberUserUpdateReqVO updateReqVO = new BlindMemberUserUpdateReqVO();
        updateReqVO.setId(loginUserId);
        updateReqVO.setRecommendBegin(LocalDateTime.now());
        updateReqVO.setRecommendEnd(nowDateTimePlus1);
        memberUserService.updateMemberUser(updateReqVO);
        return success(true);
    }


    /**
     * app前台相关用户数据
     *
     * @param blindMemberUserRespVO
     */
    private void buildBlindMemberUserRespVO(BlindMemberUserRespVO blindMemberUserRespVO, BlindMemberUserDO loginMemberUser) {
        //当前登录人
        if (Objects.nonNull(loginMemberUser)) {
            //构建地理位置 距离多少km
            String userPosition = loginMemberUser.getPosition();
            String matchPosition = blindMemberUserRespVO.getPosition();
            if (StringUtils.isNotEmpty(userPosition) && StringUtils.isNotEmpty(matchPosition)) {
                DecimalFormat df = new DecimalFormat("#0.00");
                String[] userPositionSplit = userPosition.split(",");
                String[] matchPositionSplit = matchPosition.split(",");
                double distance = NumberUtils.getDistance(Double.parseDouble(userPositionSplit[0]), Double.parseDouble(userPositionSplit[1]),
                        Double.parseDouble(matchPositionSplit[0]), Double.parseDouble(matchPositionSplit[1]));
                blindMemberUserRespVO.setGetDistance(String.valueOf(df.format(distance)));
            } else {
                blindMemberUserRespVO.setGetDistance(null);
            }
        }
        //地址信息
        buildAreaName(blindMemberUserRespVO);
        //补充枚举名称
        sysDictEnumUtil.suppleNameDict(blindMemberUserRespVO);
        //用户动态
        BlindMemberMomentExportReqVO momentReqVO = new BlindMemberMomentExportReqVO();
        momentReqVO.setUserId(blindMemberUserRespVO.getId());
        blindMemberUserRespVO.setBlindMemberMomentDOList(blindMemberMomentService.getMemberMomentList(momentReqVO));
        //是否实名
        blindMemberUserRespVO.setHaveNameAuth(blindMemberUserRespVO.getHaveReal());
        // IP属地
        if (StringUtils.isNotBlank(blindMemberUserRespVO.getRegisterIp())) {
            Area area = IPUtils.getArea(blindMemberUserRespVO.getRegisterIp());
            String city = AreaUtils.format(area.getId());
            blindMemberUserRespVO.setIpCity(city);
        }
        //用户相册
        BlindMemberAlbumExportReqVO albumReqVO = new BlindMemberAlbumExportReqVO();
        albumReqVO.setUserId(blindMemberUserRespVO.getId());
        blindMemberUserRespVO.setAlbumDOS(memberAlbumService.getMemberAlbumList(albumReqVO));
        //用户标签
        MemberUsertagExportReqVO exportReqVO = new MemberUsertagExportReqVO();
        exportReqVO.setUserId(blindMemberUserRespVO.getId());
        List<MemberUsertagDO> memberUsertagList = memberUsertagService.getMemberUsertagList(exportReqVO);
        blindMemberUserRespVO.setMemberUserTagRespVOS(MemberUsertagConvert.INSTANCE.convertList(memberUsertagList));
        //设置背景图
        Byte sex = 1;
        if (Objects.equals(blindMemberUserRespVO.getSex(), sex)) {
            blindMemberUserRespVO.setBgUrl(backgroundService.getRandomBackground(3));
        } else {
            blindMemberUserRespVO.setBgUrl(backgroundService.getRandomBackground(4));
        }
    }

    /**
     * 构建地址信息
     *
     * @param blindMemberUserRespVO
     */
    private void buildAreaName(BlindMemberUserRespVO blindMemberUserRespVO) {
        if (StringUtils.isNotBlank(blindMemberUserRespVO.getAreaId())) {
            String areaId = blindMemberUserRespVO.getAreaId();
            if (Objects.nonNull(areaId) && StringUtils.isNotEmpty(areaId)) {
                blindMemberUserRespVO.setAreaName(AreaUtils.getAreaName(areaId));
            }
        }
        if (StringUtils.isNotBlank(blindMemberUserRespVO.getNativePlace())) {
            String nativePlace = blindMemberUserRespVO.getNativePlace();
            if (Objects.nonNull(nativePlace) && StringUtils.isNotEmpty(nativePlace)) {
                blindMemberUserRespVO.setNativePlaceName(AreaUtils.getAreaName(nativePlace));
            }
        }
        if (StringUtils.isNotBlank(blindMemberUserRespVO.getMatchWorkArea())) {
            String matchWorkArea = blindMemberUserRespVO.getMatchWorkArea();
            if (Objects.nonNull(matchWorkArea) && StringUtils.isNotEmpty(matchWorkArea)) {
                blindMemberUserRespVO.setMatchWorkAreaName(AreaUtils.getAreaName(matchWorkArea));
            }
        }
    }

    /**
     * 增加 userNo(用户编号)字段
     *
     * @param createReqVO
     */
    public void addUserNo(BlindMemberUserCreateReqVO createReqVO) {
        // 占分布式锁，去redis占坑
        Boolean lock = redisTemplate.opsForValue().setIfAbsent("SysUserLock" + createReqVO.getMobile(), "value", 30, TimeUnit.SECONDS);
        if (lock) {
            //加锁成功...
            BlindMemberUserDO blindMemberUserDO = memberUserService.getMemberUserTodayLast(DateUtils.getTodayStart(), DateUtils.getTodayEnd());
            DecimalFormat formatCount = new DecimalFormat("0000");
            int dateTime = Integer.parseInt(DateUtils.dateTime());
            if (Objects.nonNull(blindMemberUserDO)) {
                String[] user_no = blindMemberUserDO.getUserNo().split("_");
                String lastPart = user_no[user_no.length - 1];
                if (user_no.length > 1) {
                    Integer num = Integer.parseInt(lastPart) + 1;
                    String no = formatCount.format(num);
                    createReqVO.setUserNo(PREFIX_USER + "_" + dateTime + "_" + no);
                }
            } else {
                String user_no = PREFIX_USER + "_" + dateTime + "_" + "0001";
                Integer num = memberUserService.getMemberUserNo(user_no);
                if (num == 0) {
                    createReqVO.setUserNo(user_no);
                }
            }

            redisTemplate.delete("SysUserLock" + createReqVO.getMobile());   //删除key，释放锁
        } else {
            try {
                Thread.sleep(100);   // 加锁失败，重试
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            addUserNo(createReqVO);
        }

    }


    public static void main(String[] args) {
//
//        List<BlindMemberUserRespVO> blindMemberUserRespVOS = new ArrayList<>();
//        BlindMemberUserRespVO blindMemberUserRespVO = new BlindMemberUserRespVO();
//        blindMemberUserRespVO.setHaveRecommend((byte) 1);
//        blindMemberUserRespVO.setRecommendBegin(LocalDateTime.now());
//        blindMemberUserRespVO.setRecommendEnd(LocalDateTime.now().plusDays(1L));
//        blindMemberUserRespVOS.add(blindMemberUserRespVO);
//
//
//        BlindMemberUserRespVO blindMemberUserRespVO1 = new BlindMemberUserRespVO();
//        blindMemberUserRespVO1.setHaveRecommend((byte) 0);
//        blindMemberUserRespVOS.add(blindMemberUserRespVO1);
//
//        BlindMemberUserRespVO blindMemberUserRespVO2 = new BlindMemberUserRespVO();
//        blindMemberUserRespVO2.setHaveRecommend((byte) 1);
//        blindMemberUserRespVO2.setRecommendBegin(LocalDateTime.now());
//        blindMemberUserRespVO2.setRecommendEnd(LocalDateTime.now().plusDays(1L));
//        blindMemberUserRespVOS.add(blindMemberUserRespVO2);
//
//        List<BlindMemberUserRespVO> collect = blindMemberUserRespVOS.stream()
//                .sorted(Comparator.comparing(BlindMemberUserRespVO::getHaveRecommend)
//                        .reversed().thenComparing(BlindMemberUserRespVO::getRecommendEnd, Comparator.reverseOrder()))
//                .collect(Collectors.toList());
//        System.out.println(JsonUtils.toJsonString(collect));
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime now5 = LocalDateTime.now().plusMinutes(5);
        System.out.println(Duration.between(now, now5).getSeconds());
        System.out.println(Duration.between(now, now5).getSeconds() > 10 * 60);

    }

}
